package com.logistics.material.entity.model;

import com.logistics.erp.entity.domain.ErpOrder;
import com.logistics.pick.entity.domain.PickDetail;
import com.logistics.utils.tool.StringUtils;
import lombok.Data;

import java.math.BigDecimal;

@Data
public class MaterialPickRow {

    private String id;

    // 物料名称
    private String itemName;

    // 物料编码
    private String itemCode;

    // 单位
    private String itemUnit;

    // 数量
    private BigDecimal itemQty;

    // 拣配数量
    private BigDecimal qty;

    // 领料单号
    private String erpInvBillCode;

    // 任务号
    private String taskNo;

    private String itemOpNo;

    private String itemSeqNo;

    private String deptCode;

    private String deptName;

    private String wcCode;

    private String wcName;

    private String nextStartDate;

    private String startPoint;

    private String startPointCode;

    private String endPoint;

    private String endPointCode;

    private String location;

    public MaterialPickRow(){}

    public MaterialPickRow(ErpOrder erpOrder){
        this.itemName = erpOrder.getItemName();
        this.itemCode = erpOrder.getItemCode();
        this.itemQty = erpOrder.getQty();
        this.itemUnit = erpOrder.getUnitName();
        this.erpInvBillCode = erpOrder.getOtherBillNo();
        this.taskNo = erpOrder.getShopOrder();
        this.itemOpNo = erpOrder.getOpNo();
        this.itemSeqNo = StringUtils.isNotNull(erpOrder.getSeqNo()) ? erpOrder.getSeqNo() : erpOrder.getId();
        this.deptCode = erpOrder.getDeptCode();
        this.deptName = erpOrder.getDeptName();
        this.wcCode = erpOrder.getWcCode();
        this.wcName = erpOrder.getWcName();
        this.nextStartDate = erpOrder.getNextStartDate();
        this.startPoint = erpOrder.getStartPoint();
        this.startPointCode = erpOrder.getStartPointCode();
        this.endPoint = erpOrder.getEndPoint();
        this.endPointCode = erpOrder.getEndPointCode();
        this.qty = StringUtils.isNotNull(erpOrder.getQty()) ? erpOrder.getQty() : BigDecimal.ZERO;
        this.location = erpOrder.getLocation();
    }

    public static MaterialPickRow build(ErpOrder erpOrder){
        return new MaterialPickRow(erpOrder);
    }

    public static MaterialPickRow build(PickDetail detail){
        MaterialPickRow materialPickRow = new MaterialPickRow();
        materialPickRow.setId(detail.getId().toString());
        materialPickRow.setItemCode(detail.getItemCode());
        materialPickRow.setItemName(detail.getItemName());
        materialPickRow.setItemQty(detail.getItemQty());
        materialPickRow.setQty(detail.getQty());
        materialPickRow.setItemUnit(detail.getItemUnit());
        materialPickRow.setTaskNo(detail.getItemWorkcode());
        materialPickRow.setItemOpNo(detail.getItemOpNo());
        return materialPickRow;
    }
}
